//
//  NSObject+Extend.m
//  Test
//
//  Created by lizq on 15/9/2.
//  Copyright (c) 2015年 lizq. All rights reserved.
//

#import "NSObject+Extend.h"
#import <objc/runtime.h>

void runAddMethod(id self, SEL sel, NSString *string){
    NSString *methodName = NSStringFromSelector(sel);
    NSLog(@"No %@ method :%@", methodName,string);
}

@implementation NSObject (Extend)

/*
+ (BOOL)resolveInstanceMethod:(SEL)sel {
    NSLog(@"%@",NSStringFromSelector(_cmd));
    NSLog(@"InstanceMethod:%@",NSStringFromSelector(sel));
    if([NSStringFromSelector(sel) isEqualToString:@"click"]) {
        class_addMethod([self class], sel, (IMP)runAddMethod, "v@:@""");
    }
    return YES;
}

+ (BOOL)resolveClassMethod:(SEL)sel {
    NSLog(@"%@",NSStringFromSelector(_cmd));
    NSLog(@"ClassMethod:%@",NSStringFromSelector(sel));
    return YES;
}

- (id)forwardingTargetForSelector:(SEL)aSelector {
    NSLog(@"%@",NSStringFromSelector(_cmd));
    NSLog(@"%@",NSStringFromSelector(aSelector));
    return self;
}
 */

- (void)forwardInvocation:(NSInvocation *)anInvocation {
    NSLog(@"%@",NSStringFromSelector(_cmd));
    if([self respondsToSelector:[anInvocation selector]])
    {
        [anInvocation invokeWithTarget:self];
    }
}

- (NSMethodSignature *)methodSignatureForSelector:(SEL)aSelector {
    NSMethodSignature *sig = [[NSNull class] instanceMethodSignatureForSelector:aSelector];
    if(sig == nil) {
        sig = [NSMethodSignature signatureWithObjCTypes:"@^vc"];
    }
    return sig;
}



@end
